/**
 * @summary 关注
*/
import req from '@/utils/request';
import * as URL from '@/constants/api'

export function follow(id) {
  return req({
    url: URL.FOLLOW,
    method: 'post',
    data: {
      target: id,
    }
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}
// 登录
export function login(params) {
  return req({
    url: URL.LOGIN,
    method: 'post',
    data: params,
  })
    .then(res => {
      localStorage.setItem('TOKEN', `Bearer ${res.data.data.token}`)
      return res.data.message
    })
    .catch(err => Promise.reject(err.response.data.message));
}
// 评论
export function comments(params) {
  return req({
    url: URL.COMMENTS,
    method: 'post',
    data: params,
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}
// 点赞
export function like(params) {
  return req({
    url: URL.LIKE,
    method: 'post',
    data: params,
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}
// 取消点赞
export function deleteLike(id) {
  return req({
    url: URL.LIKE + '/' + id,
    method: 'delete',
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}

// 收藏
export function collections(params) {
  return req({
    url: URL.COLLECTIONS,
    method: 'post',
    data: params,
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}
// 取消收藏
export function deleteCollections(id) {
  return req({
    url: URL.COLLECTIONS + '/' + id,
    method: 'delete',
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}
// 获取用户个人信息
export function getUserProfile() {
  return req({
    url: URL.USER,
  })
    .then(res => res.data.data)
    .catch(err => Promise.reject(err.response.data.message));
}
